package net.maku.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;
import net.maku.bean.vo.WebPayConfigVO;
import net.maku.constant.CaffeineKeyConstant;
import net.maku.convert.WebPayConfigConvert;
import net.maku.convert.WebTradeRecordConvert;
import net.maku.entity.WebPayConfigEntity;
import net.maku.utils.CaffeineUtils;
import net.maku.utils.MyBeanUtils;


@Service
@AllArgsConstructor
public class BizTradeServiceImpl {

	public List<WebPayConfigVO> getPayConfig() {
		 List<WebPayConfigVO> tlist = (List<WebPayConfigVO>) CaffeineUtils.getCache( CaffeineKeyConstant.PAY_TYPE_KEY );
		 if(tlist==null || tlist.size()<=0) {
			 List<WebPayConfigEntity> list = webPayConfigServiceImpl.list();
			 System.out.println("getPayConfig: "+ list.toString() );
			 //tlist = WebPayConfigConvert.INSTANCE.convertList(list);
			 tlist = MyBeanUtils.copyObjToList(list, WebPayConfigVO.class);
			 CaffeineUtils.putCache( CaffeineKeyConstant.PAY_TYPE_KEY, list );
			 Map<String, WebPayConfigVO> map = new HashMap<String, WebPayConfigVO>();
			 for(int i=0; i<tlist.size(); i++ ) {
				 map.put(tlist.get(i).getBuytype(), tlist.get(i));
			 }
			 CaffeineUtils.putCache( CaffeineKeyConstant.PAY_TYPE_KEY_MAP, map );
		 }

		 /*
		 List<WebPayConfigVO> tlist = new ArrayList<WebPayConfigVO>();
		 for(int i=0; i<list.size(); i++ ) {
			 tlist.add(WebPayConfigConvert.INSTANCE.convert(list.get(i)) );
		 }
		 List<WebPayConfigVO> tlist = MyBeanUtils.copyObjToList(list, WebPayConfigVO.class);
		 */
		 return tlist;
	 }
	 
	 @Autowired
	 WebPayConfigServiceImpl webPayConfigServiceImpl;

}
